package com.example.practice;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class Fragment_1 extends Fragment {


    private List<Fragment> fragmentList = new ArrayList<>();
    private FragmentPagerAdapter fragmentPagerAdapter;
    private ViewPager pager_vp;
    private View view;
    private TabLayout tab_layout;


    public Fragment_1() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_1, container, false);
        initView();
        setFragment();
        return view;

    }

    private void setFragment() {
        Fragment1 fragment1 = new Fragment1();
        Fragment2 fragment2 = new Fragment2();
        Fragment3 fragment3 = new Fragment3();
        fragmentList.add(fragment1);
        fragmentList.add(fragment2);
        fragmentList.add(fragment3);
        fragmentPagerAdapter = new FragmentAdpter(getChildFragmentManager(), fragmentList);
        pager_vp.setAdapter(fragmentPagerAdapter);
        pager_vp.setCurrentItem(0);
        tab_layout.setupWithViewPager(pager_vp);

    }


    private void initView() {
        pager_vp = (ViewPager) view.findViewById(R.id.pager_vp);
        tab_layout = (TabLayout) view.findViewById(R.id.tab_layout);
    }


}
